package com.ruoyi.business.controller.fuyou;

import com.ruoyi.business.service.IWsdCanteenBalanceService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.WsdCanteenBalance;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 饭堂余额，记录学生在学校饭堂的总充值金额和总退款金额Controller
 *
 * @author ruoyi
 * @date 2024-05-22
 */
@RestController
@RequestMapping("wsd_balance")
public class WsdCanteenBalanceController extends BaseController {

    @Autowired
    private IWsdCanteenBalanceService wsdCanteenBalanceService;

    /**
     * 查询饭堂余额，记录学生在学校饭堂的总充值金额和总退款金额列表
     */
    @PreAuthorize("@ss.hasPermi('business:balance:list')")
    @GetMapping("/list")
    public TableDataInfo list(WsdCanteenBalance wsdCanteenBalance) {
        startPage();
        List<WsdCanteenBalance> list = wsdCanteenBalanceService.selectWsdCanteenBalanceList(wsdCanteenBalance);
        return getDataTable(list);
    }

    /**
     * 导出饭堂余额，记录学生在学校饭堂的总充值金额和总退款金额列表
     */
    @PreAuthorize("@ss.hasPermi('business:balance:export')")
    @Log(title = "饭堂余额，记录学生在学校饭堂的总充值金额和总退款金额", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WsdCanteenBalance wsdCanteenBalance) {
        List<WsdCanteenBalance> list = wsdCanteenBalanceService.selectWsdCanteenBalanceList(wsdCanteenBalance);
        ExcelUtil<WsdCanteenBalance> util = new ExcelUtil<WsdCanteenBalance>(WsdCanteenBalance.class);
        util.exportExcel(response, list, "饭堂余额，记录学生在学校饭堂的总充值金额和总退款金额数据");
    }

    /**
     * 获取饭堂余额，记录学生在学校饭堂的总充值金额和总退款金额详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:balance:query')")
    @GetMapping(value = "/{balanceId}")
    public AjaxResult getInfo(@PathVariable("balanceId") String balanceId) {
        return success(wsdCanteenBalanceService.selectWsdCanteenBalanceByBalanceId(balanceId));
    }

    /**
     * 新增饭堂余额，记录学生在学校饭堂的总充值金额和总退款金额
     */
    @PreAuthorize("@ss.hasPermi('business:balance:add')")
    @Log(title = "饭堂余额，记录学生在学校饭堂的总充值金额和总退款金额", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WsdCanteenBalance wsdCanteenBalance) {
        return toAjax(wsdCanteenBalanceService.insertWsdCanteenBalance(wsdCanteenBalance));
    }

    /**
     * 修改饭堂余额，记录学生在学校饭堂的总充值金额和总退款金额
     */
    @PreAuthorize("@ss.hasPermi('business:balance:edit')")
    @Log(title = "饭堂余额，记录学生在学校饭堂的总充值金额和总退款金额", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WsdCanteenBalance wsdCanteenBalance)
    {
        return toAjax(wsdCanteenBalanceService.updateWsdCanteenBalance(wsdCanteenBalance));
    }

    /**
     * 删除饭堂余额，记录学生在学校饭堂的总充值金额和总退款金额
     */
    @PreAuthorize("@ss.hasPermi('business:balance:remove')")
    @Log(title = "饭堂余额，记录学生在学校饭堂的总充值金额和总退款金额", businessType = BusinessType.DELETE)
	@DeleteMapping("/{balanceIds}")
    public AjaxResult remove(@PathVariable String[] balanceIds) {
        return toAjax(wsdCanteenBalanceService.deleteWsdCanteenBalanceByBalanceIds(balanceIds));
    }
}
